<?php
namespace App\Services\Base;

use App\Models\Base\UserModel;
use App\Models\Trade\Shop\ShopModel;
use App\Exceptions\Response\Service\ServiceException;
use App\Exceptions\Response\Service\ServiceCode;

class UserService
{

    /**
     * 获取登录用户数据
     *
     * @param $id 用户ID            
     * @throws ServiceException
     * @return array
     */
    public function findSignUser($id)
    {
        $user = UserModel::findBySign($id)->shift();
        if (! $user) {
            throw new ServiceException(ServiceCode::SERVICE_USER_NOT_EXIST);
        }
        $shop = ShopModel::findByUserId($user['id'])->shift();
        if ($shop) {
            $user['shop_id'] = $shop['id'];
        }
        return $user;
    }
}